//
//  BuyerTableViewController.m
//  BingoWaterfallFlowDemo
//
//  Created by giikylee on 16/8/25.
//  Copyright © 2016年 Bing. All rights reserved.
//

#import "BuyerTableViewController.h"
#import "BuyshowTableViewCell.h"
#import "CountBuyViewController.h"
@interface BuyerTableViewController ()
@property (nonatomic,assign)CGFloat heightImage;
@end
static NSString *cellid = @"BuyshowTableViewCell";
@implementation BuyerTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self.tableView registerClass:[BuyshowTableViewCell class] forCellReuseIdentifier:cellid];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return 10;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BuyshowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
    if (!cell) {
        cell = [[BuyshowTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellid];
    }
    
    cell.shopImageView.image = [UIImage imageNamed:@"ss_fm.jpg"];
    _heightImage = 800/600 *(wKscreen - 40);
    cell.shopImageView.frame = CGRectMake(20, 10, wKscreen-40, _heightImage);
    cell.countLbl.center = CGPointMake(wKscreen/2, _heightImage/2);
    cell.countLbl.bounds = CGRectMake(0, 0, 100, 100);
    cell.headImageView.image = [UIImage imageNamed:@"2.jpg"];
    cell.headImageView.frame = CGRectMake(20, CGRectGetMaxY(cell.shopImageView.frame), 50, 50);
    cell.nameLbl.text = @"款姐刘";
    cell.nameLbl.frame = CGRectMake(CGRectGetMaxX(cell.headImageView.frame), CGRectGetMaxY(cell.shopImageView.frame) +20, 100, 20);
    cell.timeLbl.text = @"2016-08-08";
    cell.timeLbl.frame = CGRectMake(wKscreen-20-100, CGRectGetMaxY(cell.shopImageView.frame) +20, 100, 20);
    cell.detailLbl.text = @"   中国历史上著名的美玉，在他流传的数百年间，被奉为无价之宝的天下所共传之宝";
    cell.detailLbl.frame = CGRectMake(20, CGRectGetMaxY(cell.headImageView.frame), wKscreen-40, [self heightForString:cell.detailLbl.text]);
    // Configure the cell...
    cell.backLbl.frame = CGRectMake(10, 0, wKscreen-20, _heightImage + CGRectGetHeight(cell.headImageView.frame) + [self heightForString:cell.detailLbl.text]+20);
    return cell;
}
-(CGFloat)heightForString:(NSString *)str
{
    CGRect rect = [str boundingRectWithSize:CGSizeMake(wKscreen-20, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil];
    return rect.size.height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 5+_heightImage+50+60;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CountBuyViewController *cVC = [[CountBuyViewController alloc]init];
    [self.navigationController pushViewController:cVC animated:YES];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
